
use ethereum_types::{H256, Address};
use log::warn;
use super::{
    WhiteUserSet
};
use common_types::{
    engines::machine::Call,
    ids::BlockId,
};
pub struct SimpleList {
    pub(crate) whiteusers: Vec<Address>,
}

impl SimpleList{
    pub fn new(whiteusers: Vec<Address>) -> Self {
        let whiteuser_count = whiteusers.len();
        // if whiteuser_count == 1 {
        //     warn!(target: "engine", "Running AuRa with a single validator implies instant finality. Use a database?");
        // } else if validator_count != 0 && validator_count % 2 == 0 {
        //     warn!(target: "engine", "Running AuRa with an even number of validators ({}) is not recommended (risk of network split).", validator_count);
        // }
        if(whiteuser_count == 0) {
            warn!("the whiteuser count is 0,which means that no one can invoke transaction");
        }
        SimpleList { whiteusers }
    }

    /// Convert into inner representation.
    pub fn into_inner(self) -> Vec<Address> {
        self.whiteusers
    }
}
impl From<Vec<Address>> for SimpleList{
    fn from(whiteusers:Vec<Address>) -> Self{
        SimpleList{
            whiteusers
        }
    }
}
// whiteusrslist要实现whiteuserset的特性
// 规定的特性包括获得whiteusers列表，获得whiteuser的数量，判断某个人是不是whiteuser

impl WhiteUserSet for SimpleList{
    // 判断是否包含address
    fn contains(&self, address: &Address) -> bool {
        self.whiteusers.contains(address)
    }

    fn count(&self) -> usize {
        self.whiteusers.len()
    }

    fn contains_with_caller(&self, address: &Address, _: &Call) -> bool {
        self.whiteusers.contains(address)
    }

    fn defalult_caller(&self) -> Box<Call> {
        Box::new(|_, _| Err("Simple list doesn't require calls.".into()))
    }
}